package edu.scau.web.logs;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.scau.core.constants.AjaxResult;
import edu.scau.core.constants.HttpStatus;
import edu.scau.pos.vo.ProductVo;
import edu.scau.tool.sevice.LogsService;
import edu.scau.tool.vo.LogsVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/logs")
@Tag(name = "日志管理")
public class LogsController {
    @Autowired
    private LogsService logsService;
    @Operation(
            summary = "获取日志列表",
            description = "获取日志列表,访问权限:Admin",
            responses = {
                    @ApiResponse(content = @Content(mediaType = "application/json", schema = @Schema(implementation = LogsVo.class))),
            }
    )
    @PreAuthorize("hasAnyAuthority('admin')")
    @GetMapping("/listAll")
    public AjaxResult listAll(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize
    ) {
        PageHelper.startPage(pageNum, pageSize);
        List<LogsVo> logsVoList=logsService.listAll();
        PageInfo<LogsVo> pageInfo = new PageInfo<>(logsVoList);
        return AjaxResult.success(pageInfo);
    }


}
